package com.note.chh.notebook.UI.enjoy.netMusicFragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.note.chh.notebook.Adapter.SingerTypeAdapter;
import com.note.chh.notebook.Model.SingerTypeModel;
import com.note.chh.notebook.R;
import com.note.chh.notebook.UI.base.BaseFragment;
import com.note.chh.notebook.UI.enjoy.singerlist.SingerListActivity;
import com.note.chh.notebook.Uitls.gson.GsonImpl;

import java.util.List;

import butterknife.BindView;

/**
 * A simple {@link Fragment} subclass.
 * 歌手
 */

public class SingerFragment extends BaseFragment {


    @BindView(R.id.mRecycle_singer)
    RecyclerView mRecycleSinger;
    private BaseQuickAdapter singerTypeAdapter;

    public SingerFragment() {
        // Required empty public constructor
    }

    @Override
    public int bindLayout() {
        return R.layout.fragment_singer;
    }

    @Override
    public void initView(View view) {
        mRecycleSinger.setLayoutManager(new LinearLayoutManager(getActivity()));
        singerTypeAdapter = new SingerTypeAdapter(R.layout.item_singer_type);
        singerTypeAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mRecycleSinger.setAdapter(singerTypeAdapter);

    }

    @Override
    public void initData() {
        getSingerType();
    }

    @Override
    public void initListener() {
        super.initListener();
        singerTypeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                SingerTypeModel.ListBean listBean = (SingerTypeModel.ListBean) adapter.getData().get(position);
                Bundle bundle = new Bundle();
                bundle.putInt("classId",listBean.getClassid());
                bundle.putString("className",listBean.getClassname());
                startActivity(SingerListActivity.class,bundle);
            }
        });

    }

    //获取歌手类别
    private void getSingerType(){

        OkGo.<String>get("http://m.kugou.com/singer/class&json=true")
                .tag(this)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        SingerTypeModel singerTypeModel = GsonImpl.get().toObject(response.body(), SingerTypeModel.class);
                        List<SingerTypeModel.ListBean> list = singerTypeModel.getList();
                        singerTypeAdapter.setNewData(list);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);

                    }
                });
    }

}
